﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

//Write a program that finds the maximal sequence of equal elements in an array.
//		Example: {2, 1, 1, 2, 3, 3, 2, 2, 2, 1}  {2, 2, 2}.

namespace _04SequenceEqualElements
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Size of the array:");
            string strArraysize = Console.ReadLine();
            int arraySize = int.Parse(strArraysize);
            string[] array = new string[arraySize];
            for (int i = 0; i < array.Length; i++)
            {
                Console.Write("array[{0}]:", i);
                array[i] = Console.ReadLine();
            }
            Console.WriteLine("The array looks like this:");
            foreach (var item in array)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();
            int bestSequence = 1;
            int currentSequence = 1;
            string bestElement = array[1];
            for (int i = 0; i < array.Length - 1; i++)
            {
                if (array[i] == array[i + 1])
                {
                    currentSequence++;
                }
                else
                {
                    currentSequence = 1;
                }
                if (currentSequence > bestSequence)
                {
                    bestSequence = currentSequence;
                    bestElement = array[i];
                }
            }
            Console.WriteLine("The longest sequence of equal elements is:");
            for (int i = 0; i < bestSequence; i++)
            {
                Console.Write(bestElement + " ");
            }
        }
    }
}
